package com.ruoyi.web.controller.kubernetes;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.kubernetes.service.IKubernetesClientNamespaceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.KubernetesNamespace;
import com.ruoyi.web.service.IKubernetesNamespaceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * kubernetes_namespaceController
 *
 * @author xuchengchao
 * @date 2022-04-28
 */
@RestController
@RequestMapping("/kubernetes/namespace")
public class KubernetesNamespaceController extends BaseController
{
    @Autowired
    private IKubernetesNamespaceService kubernetesNamespaceService;

    /**
     * 查询kubernetes_namespace列表
     */
    @PreAuthorize("@ss.hasPermi('kubernets:namespace:list')")
    @GetMapping("/list")
    public TableDataInfo list(KubernetesNamespace kubernetesNamespace)
    {
        startPage();
        List<KubernetesNamespace> list = kubernetesNamespaceService.selectKubernetesNamespaceList(kubernetesNamespace);
        return getDataTable(list);
    }

    /**
     * 导出kubernetes_namespace列表
     */
    @PreAuthorize("@ss.hasPermi('kubernets:namespace:export')")
    @Log(title = "kubernetes_namespace", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KubernetesNamespace kubernetesNamespace)
    {
        List<KubernetesNamespace> list = kubernetesNamespaceService.selectKubernetesNamespaceList(kubernetesNamespace);
        ExcelUtil<KubernetesNamespace> util = new ExcelUtil<KubernetesNamespace>(KubernetesNamespace.class);
        util.exportExcel(response, list, "kubernetes_namespace数据");
    }

    /**
     * 获取kubernetes_namespace详细信息
     */
    @PreAuthorize("@ss.hasPermi('kubernets:namespace:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(kubernetesNamespaceService.selectKubernetesNamespaceById(id));
    }

    /**
     * 新增kubernetes_namespace
     */
    @PreAuthorize("@ss.hasPermi('kubernets:namespace:add')")
    @Log(title = "kubernetes_namespace", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KubernetesNamespace kubernetesNamespace)
    {
        return toAjax(kubernetesNamespaceService.insertKubernetesNamespace(kubernetesNamespace));
    }

    /**
     * 修改kubernetes_namespace
     */
    @PreAuthorize("@ss.hasPermi('kubernets:namespace:edit')")
    @Log(title = "kubernetes_namespace", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KubernetesNamespace kubernetesNamespace)
    {
        return toAjax(kubernetesNamespaceService.updateKubernetesNamespace(kubernetesNamespace));
    }

    /**
     * 删除kubernetes_namespace
     */
    @PreAuthorize("@ss.hasPermi('kubernets:namespace:remove')")
    @Log(title = "kubernetes_namespace", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(kubernetesNamespaceService.deleteKubernetesNamespaceByIds(ids));
    }
}
